package com.qdu.hyy.PopularityCount;

// ...
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class PopularityCountReducer extends Reducer<Text, MovieCountRevenueWritable, Text, Text> {
    // ...

    public void reduce(Text director, Iterable<MovieCountRevenueWritable> values, Context context) throws IOException, InterruptedException {
        int totalMovies = 0;
        double totalRevenue = 0;

        for (MovieCountRevenueWritable val : values) {
            totalMovies += val.getMovieCount().get();
            totalRevenue += val.getRevenue().get();
        }

        // 输出 (导演, 电影数量\t总票房)
        Text outputValue = new Text(totalMovies + "\t" + totalRevenue);
        context.write(director, outputValue);
    }
}